package com.usian.controller;


import com.usian.service.CSVToAduserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@RestController
@RequestMapping("/api/v1/csv")
public class CSVToAduserController {

    @Autowired
    private CSVToAduserService csvToAduserService;

    /**
     * 导出csv文件
     * @param response
     * @throws IOException
     */
    @PostMapping("/csv_export")
    public void CSVTo(HttpServletResponse response) throws IOException {
        csvToAduserService.csvTo(response);
    }


    /**
     * 导入csv文件
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/csv_import")
    public Integer CSVOut(@RequestPart("file") MultipartFile file) throws Exception {
        if (file==null){
            return 0;
        }
       return csvToAduserService.csvout(file);

    }
}
